<?php
$urllist = fopen("urllist.txt", "w+");
fwrite($urllist,$curHost.'\n');
fwrite($urllist,$curHost."trang-chu.html\n");
fwrite($urllist,$curHost."gioi-thieu.html\n");
fwrite($urllist,$curHost."lien-he.html\n");
//if($cat_pro){
//    foreach($cat_pro as $cat_p){
//        fwrite($urllist, $curHost.$curHost.str_replace(array('--','--'), '-', utf8_to_ascii($cat_p['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($cat_p['seo_key']!=''?$cat_p['seo_key']:$cat_p['name']))."/7/".$cat_p['id'].".html\n");
//    }
//}
//if($top_pro){
//    foreach($top_pro as $top_p){
//        fwrite($urllist, $curHost.$curHost.str_replace(array('--','--'), '-', utf8_to_ascii($top_p['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($top_p['seo_key']!=''?$top_p['seo_key']:$top_p['name']))."/1/".$top_p['id'].".html\n");
//    }
//}

urllist($cat_news,"news");
urllist($cat_news,"product");
fclose($urllist);
function urllist($arrItem, $type="", $parent_id = ""){
    global $curHost;
    global $urllist;
    global $top_news;
    global $top_pro;
    global $cat_new_name;
    global $cat_new_alias;
    global $cat_pro_name;
    global $cat_pro_alias;
    $_return = '';

    $parent_id = $parent_id != '' ? $parent_id : 1;
    for($i=0; $i<count($arrItem); $i++){
        if($arrItem[$i]['parent_id'] == $parent_id){
            if(countArray($arrItem,'parent_id',$arrItem[$i]['id'])){$dem=1;}
            if($type=='news'){
                if($dem>0){$MenuPage = "6-";}else{$MenuPage = "2-";}
                $link = $curHost.$arrItem[$i]['id'].'-'.utf8_to_ascii($cat_new_alias[$arrItem[$i]['parent']]!=''?$cat_new_alias[$arrItem[$i]['parent']]:$cat_new_name[$arrItem[$i]['parent']])."/".$MenuPage.utf8_to_ascii($arrItem[$i]['subject']!=''?$arrItem[$i]['subject']:$arrItem[$i]['name']).".html";
                foreach($top_news as $itemnews){
                    if($itemnews['parent_id']==$arrItem[$i]['id']){
                        fwrite($urllist, $curHost.str_replace(array('--','--'), '-', utf8_to_ascii($arrItem[$i]['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($arrItem[$i]['seo_key']!=''?$arrItem[$i]['seo_key']:$arrItem[$i]['name'])).$MenuPage.$arrItem[$i]['id'].".html\n");
                    }
                }
            }else{
                if($dem>0){$MenuPage = "4-";}else{$MenuPage = "7-";}
                $link = $curHost.$arrItem[$i]['id']."-".utf8_to_ascii($cat_pro_alias[$arrItem[$i]['parent']]!=''?$cat_pro_alias[$arrItem[$i]['parent']]:$cat_pro_name[$arrItem[$i]['parent']])."/".$MenuPage.utf8_to_ascii($arrItem[$i]['subject']!=''?$arrItem[$i]['subject']:$arrItem[$i]['name']).".html";
                foreach($top_pro as $itempro){
                    if($itempro['parent_id']==$arrItem[$i]['id']){
                        fwrite($urllist, $curHost.str_replace(array('--','--'), '-', utf8_to_ascii($arrItem[$i]['name'])).'/'.str_replace(array('--','--'), '-', utf8_to_ascii($arrItem[$i]['seo_key']!=''?$arrItem[$i]['seo_key']:$arrItem[$i]['name'])).$MenuPage.$arrItem[$i]['id'].".html\n");
                    }
                }
            }
            $_return.=fwrite($urllist, $link."\n");
            $_return.=urllist($arrItem, $type, $arrItem[$i]['id']);
            $dem=0;
        }
    }
    return $_return;
}
?>